%{
    This file is part of StemCellQC, a video bioinformatics software
    toolkit for analysis of phase contrast microscopy videos.
    Copyright 2013-2015 Vincent On. [vincenton001-at-gmail.com]

    StemCellQC is free software: you can redistribute it and/or 
    modify it under the terms of the GNU General Public License as 
    published by the Free Software Foundation, either version 3 of the 
    License, or (at your option) any later version.

    StemCellQC is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with StemCellQC.  If not, see <http://www.gnu.org/licenses/>.
%}

% function creates the cell array "features" which is the output written into an
% excel file.  Also uses stats_dt() function to find the change in
% specified variables between each frame.

function feat_out()
global mov 
global features

n = size(mov,2);


% Step 1: compile the cell array
features = cell( n, 1 );
features(1,1) = {'File'};
features(1,2) = {'ID'};
features(1,3) = {'Area'};
features(1,4) = {'Perimeter'};
features(1,5) = {'Centroid X'};
features(1,6) = {'Centroid Y'};
features(1,7) = {'Extent'};
features(1,8) = {'Solidity'};
features(1,9) = {'Orientation'};
features(1,10) = {'Major Axis'};
features(1,11) = {'Minor Axis'};
features(1,12) = {'Eccentricity'};
features(1,13) = {'Min. Radius Vector'};
features(1,14) = {'Max. Radius Vector'};
features(1,15) = {'Avg. Radius Vector'};
features(1,16) = {'Avg. intensity'};
features(1,17) = {'Max. intensity'};
features(1,18) = {'Min. intensity'};
features(1,19) = {'Ratio of bright area to total area of region'};
features(1,20) = {'Number of Protrusions'};
features(1,21) = {'Ratio of protruding area to total area of region'};
index = 21; %column of last feature

features(1,index+1) = {'Change in Area'};
features(1,index+2) = {'Change in Perimeter'};
features(1,index+3) = {'Change in Centroid'};

for k = 1 : n
    if ~isempty( mov(k).features )
        features( k+1, 1 ) = { mov(k).file };
        features( k+1, 2 ) = { k };
        features( k+1, 3 ) = mov(k).features(1);
        features( k+1, 4 ) = mov(k).features(2);
        features( k+1, 5 ) = mov(k).features(3);
        features( k+1, 6 ) = mov(k).features(4);
        features( k+1, 7 ) = mov(k).features(5);
        features( k+1, 8 ) = mov(k).features(6);
        features( k+1, 9 ) = mov(k).features(7);
        features( k+1, 10 ) = mov(k).features(8);
        features( k+1, 11 ) = mov(k).features(9);
        features( k+1, 12 ) = mov(k).features(10);
        features( k+1, 13 ) = mov(k).features(12);
        features( k+1, 14 ) = mov(k).features(13);
        features( k+1, 15 ) = mov(k).features(14);
        features( k+1, 16 ) = mov(k).features(15);
        features( k+1, 17 ) = mov(k).features(16);
        features( k+1, 18 ) = mov(k).features(17);
        features( k+1, 19 ) = mov(k).features(18);
        features( k+1, 20 ) = mov(k).features(19);
        features( k+1, 21 ) = mov(k).features(20);
    end
end

d_stats = stats_dt();
[r,c] = size(d_stats);

for i = 1:r
    for j = 1:c
        features( i+2, j+index ) = { d_stats( i, j ) };
    end
end
